<template>
	<view class="wrap">
		<u-form class="form" :model="model" :rules="rules" ref="uForm" label-position="left">
			<u-form-item label="任务类型" label-width="180"><u-input v-model="info.taskTypeName" placeholder="暂无数据" disabled type="text"></u-input></u-form-item>
			<u-form-item label="任务标题" label-width="180"><u-input v-model="info.taskTitle" type="textarea" disabled></u-input></u-form-item>
			<u-form-item label="督办字号" label-width="180"><u-input v-model="info.messageNumber" type="textarea" disabled></u-input></u-form-item>
			<u-form-item label="任务内容" label-width="180"><u-input v-model="info.taskContent" type="textarea" disabled></u-input></u-form-item>
			<u-form-item label="联系人" label-width="180"><u-input v-model="info.contactName" type="text" disabled></u-input></u-form-item>
			<u-form-item label="联系电话" label-width="180"><u-input v-model="info.contactPhone" type="text" disabled></u-input></u-form-item>
			<u-form-item label="结束时间" label-width="180"><u-input v-model="info.taskEndTimeStr" type="text" disabled></u-input></u-form-item>
			<u-form-item label="反馈截止时间" label-width="180"><u-input v-model="model.feedbackEndTimeStr" type="text" maxlength="200" disabled></u-input></u-form-item>
			<view class="pp">
				<span style="color:red" class="pp123">*</span>
				<u-form-item label="最新进展情况" prop="feedbackContent" label-width="180" label-position="top" class="ppap">
					<u-input type="textarea" placeholder="请输入最新进展情况" v-model="model.feedbackContent" height="100" width="300" maxlength="500" />
				</u-form-item>
			</view>
			<u-form-item label="存在问题" label-width="180" label-position="top">
				<u-input type="textarea" placeholder="请输入存在问题" v-model="model.feedbackAdvice" height="100" maxlength="500" />
			</u-form-item>
			<u-form-item label="拟采取的工作举措" label-width="180" label-position="top">
				<u-input type="textarea" placeholder="请输入拟采取的工作举措" v-model="model.feedbackMeasure" height="100" maxlength="500" />
			</u-form-item>
			<u-form-item label="完成进度" prop="feedbackProgress" label-width="180">
				<js-radio v-model="model.feedbackProgress" dict-type="dc_feedback_progress"></js-radio>
			</u-form-item>
			<view class="pp">
				<span style="color:red" >*</span>
				<u-form-item label="完成率" prop="feedbackRate" label-width="180">
					<u-input type="number" placeholder="请输入完成率" v-model="model.feedbackRate" maxlength="10"></u-input>
					<span class="input-group-addon">%</span>
				</u-form-item>
			</view>
			<u-form-item label="是否调度" label-width="180"><js-radio v-model="model.dispatchFlag" dict-type="sys_yes_no"></js-radio></u-form-item>
			<u-form-item v-if="model.dispatchFlag==1" label="选择调度" prop="feedbackDispatch" label-width="180">
				<js-radio v-model="model.feedbackDispatch" dict-type="dc_feedback_dispatch"></js-radio>		
			</u-form-item>
			<u-form-item label="反馈人" prop="feedbackName" label-width="180">
				<u-input v-model="model.feedbackName" placeholder="请输入反馈人" type="text" maxlength="200"></u-input>
			</u-form-item>
			<view class="pp">
				<span style="color:red" >*</span>
				<u-form-item label="反馈人电话" prop="feedbackPhone" label-width="180">
					<u-input v-model="model.feedbackPhone" placeholder="请输入反馈人电话" type="text" maxlength="200"></u-input>
				</u-form-item>
			</view>
			<u-form-item label="审核人" prop="auditorCode" label-width="180">
				<js-select
					v-model="model.auditorCodeStr"
					:items="userSelectList"
					placeholder="请选择人员"
					:tree="true"
					@confirm="LeaderOrg(arguments)"
					:label-value="model.auditorName"
					@label-input="model.auditorCode = $event"
				></js-select>
				<span class="input-group-addon" v-if="model.auditorName != ''" @click="clickX">X</span>
			</u-form-item>
			<!-- 附件 -->
			<view class="lh-mt-36 ipbox"><LhFilelist v-if="model.id" :bizKey="model.id" bizType="dcSupTaskFeedback_file" /></view>
		</u-form>
		<view class="form-footer" v-if="this.num == 1&&feedbackButtonFlag">
			<u-button class="btn" type="primary" @click="submitTemp">保存草稿</u-button>
			<u-button class="btn" type="primary" @click="submit">提交反馈</u-button>
		</view>

		<view class="shadow1" v-if="this.num == 2"></view>
	</view>
</template>
<script>
/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
import LhFilelist from '@/components/lh-filelist/lh-filelist.vue';
export default {
	components: {
		LhFilelist
	},
	data() {
		return {
			isUpdate: false,
			feedbackButtonFlag:false,
			model: {
				id: '',
				feedbackEndTimeStr: '',
				feedbackContent: '',
				feedbackAdvice: '',
				feedbackMeasure: '',
				feedbackProgress: '1',
				feedbackRate: 0,
				dispatchFlag: '0',
				feedbackName: '',
				feedbackPhone: '',
				auditorCodeStr: '',
				auditorCode: '',
				auditorName: '',
				feedbackDispatch:1
			},
			info: {
				taskTitle: '',
				taskContent: ''
			},
			userSelectList: [],
			rules: {
				feedbackContent: [
					{
						required: true,
						message: '请输入最新进展情况',
						trigger: ['change', 'blur']
					}
				],
				feedbackProgress: [
					{
						required: true,
						message: '请选择完成进度',
						trigger: ['change', 'blur']
					}
				],
				feedbackRate: [
					{
						pattern: /^(([1-9]?\d(\.\d{1,2})?)|100)$/,
						message: '请输入0-100之间的值',
						trigger: ['change', 'blur']
					},
					{
						required: true,
						message: '请输入完成率',
						trigger: ['change', 'blur']
					}
				],
				feedbackName: [
					{
						required: true,
						message: '请输入反馈人',
						trigger: ['change', 'blur']
					}
				],
				feedbackPhone: [
					{
						pattern: /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/,
						message: '请输入正确的手机号码',
						trigger: ['change', 'blur']
					},
					{
						required: true,
						message: '请输入反馈人电话',
						trigger: ['change', 'blur']
					}
				]
			}
		};
	},
	created() {
		this.num = uni.getStorageSync('goStaus');
	},
	onLoad(params) {
		this.model.feedbackName = this.vuex_user.userName;
		this.model.feedbackPhone = this.vuex_user.mobile;
		this.$u.api.taskFeedback.formDetail(params).then(res => {
			this.regTime(res.data.feedbackStartTime)
			res.data.feedbackRate = res.data.feedbackRate + '';
			Object.assign(this.model, res.data);
			if (this.model.feedbackStatus == 1 || this.model.feedbackStatus == 4 || this.model.feedbackStatus == 6 || this.model.feedbackStatus == 10) {
				this.isUpdate = true;
			}
			this.$u.api.taskFeedback.formInfo(res.data.taskId).then(res => {
				Object.assign(this.info, res.data);
			});
		});
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
		// 人员和机构数据
		this.$u.api.getLoginOffice().then(res => {
			this.$u.api.office.treeData({ isLoadUser: true, parentCode: res.employeeOffice.parentCodes }).then(res => {
				this.userSelectList = res;
			});
		});
	},
	methods: {
		regTime(d1){
			let time = new Date(d1)*1-new Date()*1
			let res = time/(1000*60*60*24)
			if(res<3){
				this.feedbackButtonFlag=true
			}
			
		},
		clickX() {
			this.model.auditorCode = '';
			this.model.auditorCodeStr = '';
			this.model.auditorName = '';
		},
		LeaderOrg(val) {
			this.model.auditorCode = val[0];
			this.model.auditorName = val[1];
		},
		submitTemp() {
			if (this.model.auditorName == '') {
				this.model.auditorCode = '';
			}
			this.model.feedbackStatus = 1;
			this.$refs.uForm.validate(valid => {
				if (valid) {
					this.$u.api.taskFeedback.feedback(this.model).then(res => {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
							success: function() {
								if (res.result == 'true') {
									uni.setStorageSync('refreshList', true);
									uni.navigateBack();
								}
							}
						});
					});
				} else {
					this.$u.toast('您填写的信息有误，请根据提示修正。');
				}
			});
		},
		submit() {
			this.model.feedbackStatus = 2;
			if (this.model.auditorName == '') {
				this.model.auditorCode = '';
			}
			this.$refs.uForm.validate(valid => {
				if (valid) {
					this.$u.api.taskFeedback.feedback(this.model).then(res => {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
							success: function() {
								if (res.result == 'true') {
									uni.setStorageSync('refreshList', true);
									uni.navigateBack();
								}
							}
						});
					});
				} else {
					this.$u.toast('您填写的信息有误，请根据提示修正。');
				}
			});
		},
		cancel() {
			uni.navigateBack();
		}
	}
};


</script>
<style lang="scss">
.pp {
	position: relative;
	display: flex;
	justify-content: left;
	align-items: center;
	width: 100%;
}
.pp123 {
	position: absolute;
	top: 20px;
	left: -2%;
}
.ppap {
	width: 100%;
}
.ipbox{
	z-index: 999;
}
.shadow1 {
	position: fixed;
	top: 5%;
	width: 100%;
	height: 100%;
	z-index: 998;
	background-color: rgba(255, 255, 255, 0.1);
}
</style>
